

/**
 * 创建entity Polygon
 */
import Entity from '../Entity'

const DEFAULT_STYLE = {
  clampToGround: true
}


export default class Polygon extends Entity {

  /**
   * 创建一个Polygon实体对象
   * @param {*} positions
   * @param {*} options 
   */
  constructor(positions, options = {}) {
    super()
    this._height = options.height || 0
    this._positions = positions
    this._type = 'polygon'
    this._style = {
      ...DEFAULT_STYLE,
      ...options
    }
    this._extrudedHeight = options.extrudedHeight
    this._holes = []
    this.delegate = new Cesium.Entity({polygon: {} })
    this.mounted()
  }

  /**
  * 初始化对象属性
  */

  mounted() {
    this.height = this._height
    this.style = this._style
    this.positions = this._positions
    this.extrudedHeight = this._extrudedHeight
    this.holes = this._holes
  }

  /** 
  * @param {*} style Circle的样式
  * @returns 
  */

  setStyle(style) {
    if (!style) return
    Object.assign(this._style , {...style})
    Object.assign(this.delegate.polygon, { ...this._style })
  }

  get height() {
    return this._height
  }

  set height(val) {
    this._height = val
    this.delegate.polygon.extrudedHeight = this._height
  }

  get extrudedHeight() {
    return this._extrudedHeight
  }

  set extrudedHeight(val) {
    this._extrudedHeight = val
    this.delegate.polygon.extrudedHeight = this._extrudedHeight
  }

  get holes(){
    return this._holes
  }

  set holes(val){
    this._holes = val
    this.delegate.polygon.hierarchy = {
      positions : this._positions,
      holes : [{
        positions : this._holes
      }]
    }
  }
  
  get positions(){
    return this._positions
  }

  set positions(val){
    this._positions = val
    this.delegate.polygon.hierarchy = this._positions
  }

  get style(){
    return this._style
  }

  set style(val){
    Object.assign(this._style , {...val})
    Object.assign(this.delegate.polygon , {...this._style})
  }
}
